import itertools

# a = '100000'
# b='010000'
# print((int(a,2) & int(b,2) == 0))
#
# t2 = 10
# t1 = 2
# print(f"第个方案生成成功。用时：{t2 - t1}")
#
# t=[]
# d=(1, 1, 1, 180, True)
# a=[(242, 0), (268, 0), (190, 4)]
# # b=[('1000000', 96, 18, '011110000000000000', 0), ('0100000', 96, 18, '011110000000000000', 0), ('0010000', 96, 18, '011110000000000000', 0), ('0001000', 96, 18, '011110000000000000', 0), ('0000100', 96, 18, '011110000000000000', 0), ('1000000', 106, 18, '011110000000000000', 0), ('0100000', 106, 18, '011110000000000000', 0), ('0010000', 106, 18, '011110000000000000', 0), ('0001000', 106, 18, '011110000000000000', 0), ('0000100', 106, 18, '011110000000000000', 0), ('1000000', 116, 18, '011110000000000000', 0), ('0100000', 116, 18, '011110000000000000', 0), ('0010000', 116, 18, '011110000000000000', 0), ('0001000', 116, 18, '011110000000000000', 0), ('0000100', 116, 18, '011110000000000000', 0), ('1000000', 126, 18, '011110000000000000', 0), ('0100000', 126, 18, '011110000000000000', 0), ('0010000', 126, 18, '011110000000000000', 0), ('0001000', 126, 18, '011110000000000000', 0), ('0000100', 126, 18, '011110000000000000', 0), ('1000000', 136, 18, '011110000000000000', 0), ('0100000', 136, 18, '011110000000000000', 0), ('0010000', 136, 18, '011110000000000000', 0), ('0001000', 136, 18, '011110000000000000', 0), ('0000100', 136, 18, '011110000000000000', 0), ('1000000', 146, 18, '011110000000000000', 0), ('0100000', 146, 18, '011110000000000000', 0), ('0010000', 146, 18, '011110000000000000', 0), ('0001000', 146, 18, '011110000000000000', 0), ('0000100', 146, 18, '011110000000000000', 0), ('1000000', 156, 18, '011110000000000000', 0), ('0100000', 156, 18, '011110000000000000', 0), ('0010000', 156, 18, '011110000000000000', 0), ('0001000', 156, 18, '011110000000000000', 0), ('0000100', 156, 18, '011110000000000000', 0), ('1000000', 166, 18, '011110000000000000', 0), ('0100000', 166, 18, '011110000000000000', 0), ('0010000', 166, 18, '011110000000000000', 0), ('0001000', 166, 18, '011110000000000000', 0), ('0000100', 166, 18, '011110000000000000', 0), ('1000000', 176, 18, '011110000000000000', 3), ('0100000', 176, 18, '011110000000000000', 3), ('0010000', 176, 18, '011110000000000000', 3), ('0001000', 176, 18, '011110000000000000', 3), ('0000100', 176, 18, '011110000000000000', 3), ('1000000', 186, 18, '011110000000000000', 3), ('0100000', 186, 18, '011110000000000000', 3), ('0010000', 186, 18, '011110000000000000', 3), ('0001000', 186, 18, '011110000000000000', 3), ('1000000', 196, 18, '011110000000000000', 4), ('0100000', 196, 18, '011110000000000000', 4), ('0010000', 196, 18, '011110000000000000', 4), ('0001000', 196, 18, '011110000000000000', 4), ('1000000', 206, 18, '011110000000000000', 5), ('0100000', 206, 18, '011110000000000000', 5), ('0010000', 206, 18, '011110000000000000', 5), ('0001000', 206, 18, '011110000000000000', 5), ('1000000', 216, 18, '011110000000000000', 5), ('0100000', 216, 18, '011110000000000000', 5), ('0010000', 216, 18, '011110000000000000', 5), ('0001000', 216, 18, '011110000000000000', 5), ('1000000', 226, 18, '011110000000000000', 8), ('0100000', 226, 18, '011110000000000000', 8), ('0010000', 226, 18, '011110000000000000', 8), ('0001000', 226, 18, '011110000000000000', 8)]
# # c = list(itertools.product(a,b))
# # t.append([d,c])
# # print(t)
#
# a1 = (1, 10)
# a2 = ('0000001', 96, 18, '000000000000000100', 0)
# a3 = a1 + (a2,)
# print(a3)
#
# c= ((0,0),(111,22,5,6,0))
# print(c)
#
# c2 = [4,5,6]
# c1 = [1,2]
# tuple(c1)
# c2.append(c1)
# print(c2)
#
# a1 = (200,4)
# t1 = ((20,200),(456,6,5,True))
# t.append(a1 + t1)
# print(t)
# #
# # t.append(((200,0,True) + ((0,0),a1)))
# # print(t)
#
# print(4,5)
#
# # q1,q2= (276, 1), ('0100000', 204, 36, '011111111111100111', 0)
# # q3 = ((276, 1),q2)
# # print(q3)
#
# b1 = (2,3)
# b2 = [b1+(sum(b1),)]
# print(b2)

# def min_cut_cost(n, nums):
#     # 计算整个序列的总和
#     total_sum = sum(nums)
#
#     # 初始化左侧子序列的累加和和最小代价
#     left_sum = 0
#     min_cost = float('inf')
#
#     # 遍历序列，寻找最小切割代价
#     for i in range(n - 1):
#         left_sum += nums[i]
#         right_sum = total_sum - left_sum
#         current_cost = left_sum * right_sum
#
#         if current_cost < min_cost:
#             min_cost = current_cost
#
#     return min_cost
#
#
# # 示例输入
# n = int(input())
# nums = list(map(int, input().split()))
#
# # 调用函数并输出结果
# print(min_cut_cost(n, nums))

# import math
#
#
# # 计算两点之间的欧几里得距离
# def distance(x1, y1, x2, y2):
#     return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
#
#
# # 使用并查集（Disjoint Set Union, DSU）来维护连通性
# class DSU:
#     def __init__(self, n):
#         self.parent = list(range(n))
#         self.rank = [1] * n
#
#     # 查找根节点并进行路径压缩
#     def find(self, x):
#         if self.parent[x] != x:
#             self.parent[x] = self.find(self.parent[x])
#         return self.parent[x]
#
#     # 合并两个集合
#     def union(self, x, y):
#         rootX = self.find(x)
#         rootY = self.find(y)
#         if rootX != rootY:
#             if self.rank[rootX] > self.rank[rootY]:
#                 self.parent[rootY] = rootX
#             elif self.rank[rootX] < self.rank[rootY]:
#                 self.parent[rootX] = rootY
#             else:
#                 self.parent[rootY] = rootX
#                 self.rank[rootX] += 1
#             return True
#         return False
#
#
# # Kruskal算法求最小生成树
# def kruskal(n, edges):
#     dsu = DSU(n)
#     edges.sort(key=lambda x: x[2])  # 按照边的权重排序
#     total_cost = 0
#     for u, v, w in edges:
#         if dsu.union(u, v):
#             total_cost += w
#     return total_cost
#
#
# # 读取输入
# n = int(input())  # 城市数量
# cities = [tuple(map(int, input().split())) for _ in range(n)]
#
# # 构建所有边
# edges = []
# for i in range(n):
#     for j in range(i + 1, n):
#         dist = distance(cities[i][0], cities[i][1], cities[j][0], cities[j][1])
#         edges.append((i, j, dist))
#
# # 求最小生成树的总权重
# min_years = kruskal(n, edges)
#
# # 向上取整并输出结果
# print(math.ceil(min_years))

# def simulate_timers(m, periods):
#     result = []
#     for time in range(1, m + 1):  # 从1开始以避免0时刻触发
#         for period in periods:
#             if time % period == 0:
#                 result.append(str(period))
#     return ' '.join(result)
#
# # 读取输入
# m = int(input())
# periods = list(map(int, input().split()))
#
# # 调用函数并打印结果
# print(simulate_timers(m, periods))

# def can_fill_box(N, n, c, toys):
#     # 初始化dp数组，dp[i]表示容量为i时是否可以恰好装满
#     dp = [False] * (N + 1)
#     dp[0] = True  # 容量为0时默认可以装满
#
#     # 先处理填充物
#     for i in range(1, N + 1):
#         if i <= c:
#             dp[i] = True
#             continue
#
#     # 处理玩具
#     for toy in toys:
#         for i in range(N, toy - 1, -1):
#             if dp[i - toy]:
#                 dp[i] = True
#
#     return "YES" if dp[N] else "NO"
#
#
# # 读取输入
# T = int(input())
# for _ in range(T):
#     N, n, c = map(int, input().split())
#     toys = list(map(int, input().split()))
#
#     # 输出结果
#     print(can_fill_box(N, n, c, toys))

# def is_sorted(arr):
#     # 检查数组是否升序或降序
#     ascending = all(arr[i] <= arr[i + 1] for i in range(len(arr) - 1))
#     descending = all(arr[i] >= arr[i + 1] for i in range(len(arr) - 1))
#     return ascending or descending
#
#
# def can_sort_arrays(a, b):
#     # 检查原始数组是否有序
#     if is_sorted(a) or is_sorted(b):
#         return "YES"
#
#     # 合并数组并检查
#     merged = a + b
#     merged.sort()
#
#     # 尝试从合并后的数组中构建新的有序数组
#     for i in range(len(a) + 1):
#         new_a = merged[:i] + merged[len(b):]
#         new_b = merged[i:i + len(b)]
#
#         if is_sorted(new_a) or is_sorted(new_b):
#             return "YES"
#
#     return "NO"
#
#
# # 读取输入
# T = int(input())
# for _ in range(T):
#     n = int(input())
#     a = list(map(int, input().split()))
#     b = list(map(int, input().split()))
#
#     # 输出结果
#     print(can_sort_arrays(a, b))

# import math
#
#
# def min_operations_to_red(T, cases):
#     results = []
#
#     for n in cases:
#         # 使用对数计算需要的操作次数
#         if n == 0:
#             operations = 0
#         else:
#             operations = math.ceil(math.log2(n))
#
#         results.append(operations)
#
#     return results
#
#
# # 输入处理
# T = int(input())
# cases = [int(input()) for _ in range(T)]
#
# # 计算并输出结果
# results = min_operations_to_red(T, cases)
# for result in results:
#     print(result)

def count_divisors(n):
    divisor_count = [0] * (n + 1)
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            divisor_count[j] += 1
    return divisor_count

from collections import defaultdict
import bisect

def build_count_map(divisor_count):
    count_map = defaultdict(list)
    for number in range(1, len(divisor_count)):
        count_map[divisor_count[number]].append(number)
    return count_map

def process_queries(queries, count_map):
    results = []
    for l, r, m in queries:
        if m in count_map:
            nums = count_map[m]
            left_index = bisect.bisect_left(nums, l)
            right_index = bisect.bisect_right(nums, r)
            results.append(right_index - left_index)
        else:
            results.append(0)
    return results

# 读取输入
n, q = map(int, input().split())
divisor_count = count_divisors(n)
count_map = build_count_map(divisor_count)

queries = [tuple(map(int, input().split())) for _ in range(q)]
results = process_queries(queries, count_map)

# 一次性输出所有结果
print("\n".join(map(str, results)))
